package com.mallcai.bigdata.ladon.service.report.impl.handler;

import com.mallcai.bigdata.ladon.client.vo.ReportDataVO;
import com.mallcai.bigdata.ladon.datasource.RunInfoResult;
import com.mallcai.bigdata.ladon.dpl.entity.report.Report;
import com.mallcai.bigdata.ladon.service.report.impl.ReportQueryConstants;
import com.mallcai.bigdata.ladon.service.report.impl.ReportQueryContext;
import lombok.extern.slf4j.Slf4j;
import org.springframework.core.annotation.Order;
import org.springframework.stereotype.Component;

/**
 * @author feixy
 * @version 1.0
 * @date 2019-07-19 21:00
 */
@Slf4j
@Component
@Order(2550)
public class ReportQueryFlowSwitchHandler extends AbstractReportQueryPreHandler {

    private static final RunInfoResult  EMPTY_RESULT= RunInfoResult.createEmptyResult(ReportDataVO.EMPTY);

    @Override
    public void preInternal(ReportQueryContext context) {
        Report report = context.getReport();
        boolean isFlowOff = context.getInnerParam(ReportQueryConstants.KEY_IS_FLOW_OFF);
        if(isFlowOff){
            log.info("报表[code:{}]已限流,不去数据库查询",report.getCode());
            context.setResult(EMPTY_RESULT);
        }
    }


}
